import request from '@/utils/request'
//角色管理相关接口
import type { RoleResponseData, RoleData,MenuResponseData } from './type'

//获取所有角色职位接口
export const reqAllRoleListAPT = (
  page: number,
  limit: number,
  roleName: string
) => {
  return request.get<any, RoleResponseData>(
    `/admin/acl/role/${page}/${limit}/?roleName=${roleName}`
  )
}
//获取添加或者修改角色职位的数据接口
export const reqAddOrUpdateRoleAPI = (data: RoleData) => {
  if (data.id) {
    return request.put<any, any>(`/admin/acl/role/update`, data)
  } else {
    return request.post<any, any>(`/admin/acl/role/save`, data)
  }
}
//根据角色id获取角色职位数据接口
export const reqAllMenuListAPI = (roleId: number) =>
  request.get<any, MenuResponseData>(`/admin/acl/permission/toAssign/${roleId}`)
//给角色职位分配权限接口
export const reqAssignRoleAPI = (roleId: number, permissionId: number[]) =>
  request.post<any, any>(`/admin/acl/permission/doAssign/?roleId=${roleId}&permissionId=${permissionId}`)
//删除角色职位接口
export const reqDeleteRoleAPI = (id: number) =>
  request.delete<any, any>(`/admin/acl/role/remove/${id}`)
